/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
    BlobInputList, CCell, Cell, CheckSwitch, IconCheckSquare, IconSquare, Input, InputLine, LineColumn, Select, Table, TableBody, TableRow, Text,
} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, RepLink, useItemInputControl,} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import {config设备概况} from "./orcBase";
import {useThreeColumnView} from "../../hook/useThreeColumnSubr";
import {useContext} from "react";
import UserContext from "../../../routing/UserContext";

export const itemA概况=['电厂','电厂地址','安全员','安全员电','试验单','燃验单' ];
export const DeviceSurveyPerform=
    React.forwardRef((
        { children, show ,alone=true,redId,nestMd,label,rep}:InternalItemProps,  ref
    ) => {
        const {user} = useContext(UserContext);
        const itemA = React.useMemo(() => {
            return [...itemA概况, '使用单位','使用单位地址'];
        }, []);
        const [getInpFilter]=useMeasureInpFilter(null,itemA,);
        const {inp, setInp} = useItemInputControl({ ref });
        const lst使用=[inp?.使用单位??'' ];
        const lst化验=[user?.unit?.name??'', inp?.使用单位??'' ];
        return <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show} redId={redId}
                                    nestMd={nestMd} alone={alone} label={label!}>
            <Text variant="h5">{label}：</Text>
            <LineColumn>
                <InputLine label={`用户单位(电厂)：`}>
                    <BlobInputList  value={inp?.电厂 ||''} rows={2} datalist={lst使用}
                                    onListChange={v => setInp({ ...inp, 电厂: v || undefined}) } />
                </InputLine>
                <InputLine label={`用户单位(电厂)地址：`}>
                    <BlobInputList  value={inp?.电厂地址 ||''} rows={2} datalist={[inp?.使用单位地址??'' ]}
                                    onListChange={v => setInp({ ...inp, 电厂地址: v || undefined}) } />
                </InputLine>
                <InputLine  label='联系人：' >
                    <Input  value={inp?.安全员 ||''}
                            onChange={e => setInp({ ...inp, 安全员: e.currentTarget.value}) } />
                </InputLine>
                <InputLine  label='联系电话：' >
                    <Input  value={inp?.安全员电 ||''}
                            onChange={e => setInp({ ...inp, 安全员电: e.currentTarget.value}) } />
                </InputLine>
                <InputLine label={`负责试验单位：`}>
                    <BlobInputList  value={inp?.试验单 ||''} rows={2} datalist={[user?.unit?.name??'' ]}
                                    onListChange={v => setInp({ ...inp, 试验单: v || undefined}) } />
                </InputLine>
                <InputLine label={`燃料化验单位：`}>
                    <BlobInputList  value={inp?.燃验单 ||''} rows={2} datalist={lst化验}
                                    onListChange={v => setInp({ ...inp, 燃验单: v || undefined}) } />
                </InputLine>
            </LineColumn>
        </InspectRecordLayout>;
});

export const daL试验依据=[['据性能','GB/T 10184-2015《电站锅炉性能试验规程》'],
    ['据节能','TSG 91-2021《锅炉节能环保技术规程》'],
    ['据流化','DL/T 964-2005《循环流化床锅炉性能试验规程》']
];
export const itemA下结论=['检验结论','检验日期','检验日期1','新下检日','试验结果','许压力','许温度','许介质','许其它','试验结论','参检人员'];
for(const [name,desc] of daL试验依据){
    itemA下结论.push(name);
}
const itemA下结论m=[...itemA下结论, '使用单位'];
const  结论默认='该锅炉燃烧II类烟煤时，锅炉测试热效率符合设计热效率的要求（设计热效率为87.1%），过量' +
    '空气系数符合TSG 91-2021的要求（过量空气系数≤1.4），排烟温度符合TSG 91-2021的要求' +
    '（排烟温度≤170℃）。';
export const ConclusionPerform=
React.forwardRef((
    { children, show ,alone=true,redId,nestMd,label,}:InternalItemProps,  ref
) => {
        const [getInpFilter]=useMeasureInpFilter(null,itemA下结论m,);
        const {inp, setInp} = useItemInputControl({ ref });
        const default结果=`本次试验测得 ${inp?.使用单位??''} 运行管理的UG-190/9.8-M2型燃煤循环流化床锅炉，在`+
                '测试运行工况下，燃烧II类烟煤时锅炉的平均热效率为93.38%，平均过量空气系数为1.18，平均'+
                '排烟温度为122.1℃。';
        return <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show} redId={redId}
                                    nestMd={nestMd} alone={alone} label={label!}>
            <Text variant="h5">{label}：</Text>
            试验依据：
            <LineColumn>
            { daL试验依据.map(([name,desc] : any, i:number)=> {
                return <InputLine key={i} label={`${desc}:`}>
                    <CheckSwitch  checked={inp?.[name] || false} onChange={e => setInp({...inp, [name]: inp?.[name]? undefined:true}) } />
                </InputLine>;
            }) }
            </LineColumn>
            试验结果:<br/>
            <BlobInputList  value={inp?.试验结果 ||''} rows={8} datalist={ [ default结果, ] }
                            onListChange={v => setInp({ ...inp, 试验结果: v || undefined}) } />
            试验结论:<br/>
            <BlobInputList  value={inp?.试验结论 ||''} rows={5}  datalist={ [ 结论默认, ] }
                            onListChange={v => setInp({ ...inp, 试验结论: v || undefined}) } />
            <Text variant="h5">试验结论{'>>'}</Text>
            <InputLine  label='结论' >
                <Select inputSize="md" css={{minWidth: '140px', fontSize: '1.3rem', padding: '0 1rem'}}
                        value={inp?.检验结论 || ''}
                        onChange={e => setInp({...inp, 检验结论: e.currentTarget.value || undefined})}>
                    <option></option>
                    <option>符合</option>
                    <option>不符合</option>
                </Select>
            </InputLine>
            <LineColumn>
                <InputLine label='试验人员'>
                    <BlobInputList value={inp?.参检人员 || ''} rows={2}
                                   onListChange={v => setInp({...inp, 参检人员: v || undefined}) } />
                </InputLine>
                <InputLine label='设置试验日期'>
                    <Input value={inp?.检验日期 || ''} type='date'
                           onChange={e => setInp({...inp, 检验日期: e.currentTarget.value})}/>
                </InputLine>
                <InputLine  label='试验起始日期' >
                    <Input  value={inp?.检验日期1 ||''}  type='date'
                            onChange={e => setInp({ ...inp, 检验日期1: e.currentTarget.value}) } />
                </InputLine>
            </LineColumn>
        </InspectRecordLayout>;
});


export const 检验结论报告 = ({orc, rep, theme,op}: { orc: any, rep: any, theme: any,op?:boolean}
) => {
    // const renderUpper = usePrefixDataTable({config: config设备概况, orc, rep, slash: true});
    const [renderUpper,renderGaizao]=useThreeColumnView({orc, config:config设备概况,slash:true,});
    return <>
        <Text id={'Conclusion'} variant="h2" css={{
            textAlign: 'center',
            "@media print": {pageBreakBefore: 'always',},
        }}>电站锅炉性能试验综合报告</Text>
        <Text css={{display: 'flex', flexDirection: 'row-reverse', marginRight: '2rem'
        }}>{op?'记录':'报告'}编号：{rep.isp?.no}</Text>
        <Table id='Survey' fixed={  ["13.3%","29%", "6.2%", "12.9%", "8.1%", "%"]  } css={{borderCollapse: 'collapse'}} tight miniw={800}>
            <TableBody>
                <RepLink rep={rep} tag={'Survey'}>
                    {renderUpper}
                </RepLink>
            </TableBody>
        </Table>
        <Table fixed={ ["8.5%","36%", "8.5%", "6.5%", "%"] } css={{borderCollapse: 'collapse'}} tight miniw={800}>
            <TableBody>
                <RepLink rep={rep} tag={'Conclusion'}>
                    <TableRow>
                        <Cell colSpan={5} css={{paddingLeft:'1rem'}}>
                            试验依据：
                            <div css={{display: 'flex', flexDirection: 'column', alignItems: 'flex-start'}}>
                                {daL试验依据.map(([name,desc]: any, i: number) => {
                                    return <div key={i} css={{display: 'flex', alignItems: 'center'}}>{orc?.[name] ?
                                        <IconCheckSquare size='sm'/> : <IconSquare size='sm'/>}&nbsp;{desc}</div>;
                                })}
                            </div>
                        </Cell>
                    </TableRow>
                    <TableRow>
                        <CCell>试验结果</CCell>
                        <Cell colSpan={4}>
                            <div css={{minHeight: '8rem',margin:'0.3rem',alignContent: 'center', whiteSpace: 'pre-wrap'}}>
                                {orc?.试验结果 ?? '／'}
                            </div>
                        </Cell>
                    </TableRow>
                    <TableRow>
                        <CCell>试验结论</CCell>
                        <Cell colSpan={4}>
                            <div css={{minHeight: '5rem',margin:'0.3rem',alignContent: 'center', whiteSpace: 'pre-wrap'}}>
                                {orc?.试验结论 ?? '／'}
                            </div>
                        </Cell>
                    </TableRow>
                    <TableRow>
                        <CCell colSpan={1}>试验人员</CCell>
                        <CCell colSpan={4}>{orc.参检人员 || '／'}</CCell>
                    </TableRow>
                </RepLink>
            </TableBody>
        </Table>
    </>;
};
